﻿using System;
using System.Windows.Forms;
using SuckerPunch.SettingsUI;

namespace SuckerPunch.Presenters
{
    class SettingsPresenter
    {
        private Settings _view;

        public SettingsPresenter(Settings settingsForm)
        {
            _view = settingsForm;
            WireView();
        }

        private void WireView()
        {
            _view.Load += (_view_Load);
            _view.TreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick);
        }

        private void LoadTree()
        {
            //Add nodes to tree. 'Connection' is the highest level node.
            TreeNode connectionNode = new TreeNode();
            connectionNode.Name = "Connection";
            connectionNode.Text = "Connection";
            //Servers
            TreeNode serverNode = new TreeNode();
            serverNode.Name = "Servers";
            serverNode.Text = "Servers";

            connectionNode.Nodes.Add(serverNode);

            _view.TreeView.Nodes.Add(connectionNode);

        }

        private void ShowServerUI()
        {
            
        }

        private void ShowConnectionUI()
        {
            SettingsUI.Connection connectionUI = new SettingsUI.Connection();
            ConnectionPresenter connectionPresenter = new ConnectionPresenter(connectionUI);
            _view.Controls.Add(connectionUI);
            connectionUI.Parent = _view.SettingsPanel;
        }

        void _view_Load(object sender, System.EventArgs e)
        {
            LoadTree();
        }
        void TreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            switch (e.Node.Name)
            {
                case "Connection":
                    ShowConnectionUI();
                    break;
                case "Servers":
                    ShowServerUI();
                    break;
                default:
                    break;
            }
        }

      
        
    }
}
